/*
 *
 * This is a VoIP Application designed for local-network usage for voice and
 * messaging
 * Copyright (C) 2012  Imran M Yousuf (imyousuf@smitsol.com)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.smitsol.voip.server.rtpproxy;

import com.google.inject.AbstractModule;
import org.vtlabs.rtpproxy.client.RTPProxyClient;
import org.vtlabs.rtpproxy.config.RTPProxyClientConfig;
import org.vtlabs.rtpproxy.config.RTPProxyClientConfigurator;

/**
 *
 * @author imyousuf
 */
public class RTPProxyModule extends AbstractModule {

  private final String rtpProxyServerConnxnString;

  public RTPProxyModule(String rtpProxyServerConnxnString) {
    this.rtpProxyServerConnxnString = rtpProxyServerConnxnString;
  }

  public String getRtpProxyServerConnxnString() {
    return rtpProxyServerConnxnString;
  }

  @Override
  protected void configure() {
    bind(RTPProxy.class).to(RTPProxyImpl.class);
    try {
      RTPProxyClientConfig config = RTPProxyClientConfigurator.load(rtpProxyServerConnxnString);
      bind(RTPProxyClientConfig.class).toInstance(config);
      RTPProxyClient proxyClient = new RTPProxyClient(config);
      bind(RTPProxyClient.class).toInstance(proxyClient);
    }
    catch (Exception ex) {
      throw new IllegalStateException(ex);
    }
  }
}
